package lc2;

import org.junit.Test;

public class Ex1423 {
    class Solution {
        public int maxScore(int[] nums, int k) {
            int n = nums.length;
            int sum = 0;
            for (int i = n - k; i < n - 1; i++) {
                sum += nums[i];
            }
            int max = 0;
            for (int i = n - 1; i <= n + k - 1; i++) {
                sum += nums[i % n];
                max = Math.max(max, sum);
                sum -= nums[(i - k + 1) % n];
            }
    
            return max;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{1,2,3,4,5,6,1};
        System.out.println(s.maxScore(nums, 3));



    }
}
